<template>
  <div class="base-table">
    <el-table :data="data" style="width: 100%; margin-top: 20px">
      <slot></slot>
    </el-table>

    <el-pagination
      v-if="showPagination"
      class="pagination"
      :current-page="currentPage"
      :page-size="pageSize"
      :total="total"
      layout="total, prev, pager, next"
      @current-change="handlePageChange" />
  </div>
</template>

<script setup>
import { defineProps, defineEmits } from "vue";

const props = defineProps({
  data: {
    type: Array,
    required: true,
  },
  currentPage: {
    type: Number,
    default: 1,
  },
  pageSize: {
    type: Number,
    default: 10,
  },
  total: {
    type: Number,
    default: 0,
  },
  showPagination: {
    type: Boolean,
    default: true,
  },
});

const emit = defineEmits(["update:currentPage", "page-change"]);

// 处理分页变化
const handlePageChange = (page) => {
  emit("update:currentPage", page);
  emit("page-change", page);
};
</script>

<style scoped>
.base-table {
  width: 100%;
}

.pagination {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}
</style>
